import wei.yigulu.iec104.annotation.AsduType;
import wei.yigulu.iec104.apdumodel.Apdu;
import wei.yigulu.iec104.asdudataframe.TotalSummonType;
import wei.yigulu.iec104.util.SendDataFrameHelper;


/**
 * 处理总召唤帧
 *
 * @author 修唯xiuwei
 * @version 3.0
 */
@AsduType(typeId = 100)
public class HandleTotalSummon extends TotalSummonType {


    @Override
    public byte[][] handleAndAnswer(Apdu apdu) throws Exception {
        apdu.getLog().trace("----------响应总召唤---------");
        //当该帧是由 SlaverBuilder 或其子类接收到的  且为总召唤原因为激活
        if (apdu.getAsdu().getCot().getNot() == 6) {
            //响应总召唤 激活确认帧
            SendDataFrameHelper.sendTotalSummonFrame(apdu.getChannel(), apdu.getAsdu().getCommonAddress(), 7, apdu.getLog());
            //响应遥信
            SendDataFrameHelper.sendYxDataFrame(apdu.getChannel(), ProtocolDataContainer.getInstance().getBooleans(), apdu.getAsdu().getCommonAddress(), 20, apdu.getLog());
            //响应遥测
            SendDataFrameHelper.sendYcDataFrame(apdu.getChannel(), ProtocolDataContainer.getInstance().getNumbers(), apdu.getAsdu().getCommonAddress(), 20, apdu.getLog());
            //响应总召唤 激活停止帧
            SendDataFrameHelper.sendTotalSummonFrame(apdu.getChannel(), apdu.getAsdu().getCommonAddress(), 10, apdu.getLog());
        }
        return null;
    }


}
